<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/view/include/css-include.jsp"%>
<%@ include file="/view/include/jsp-include.jsp"%>
<%@ include file="/view/include/jquery-include.jsp"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>PRODUCT ADJUST/ INSERT</title>

<script type="text/javascript">

    $().ready(function() {
        /* 달력 */
        calendar.makeCalender("adjustDate");
        
        $("#reSetBtn").bind("click",function(){
            $("form[name='productAdjustWriteFrm']").each(function(){
                  this.reset();
            });
            
        });

        $("#onList").bind("click",function(){
             location="/productAdjust.html";            
        });

        /* 저장버튼 */
        $("#saveBtn").bind("click",function(){       
            $("form[name='productAdjustWriteFrm']").submit();
        });
        
        /* textarea 체크 */
        $("#remark").bind("keyup",function(){
            textAreaKyUp(this);  //조회 직후에도 호출해야해서 function 으로 뺌.. 
        });

        /* 메인폼 서브밋 */
        $("form[name='productAdjustWriteFrm']").ajaxForm({
            dataType: "json",
            beforeSerialize: function($form, options) {
                //return $("form[name='orderFrm']").valid();  jquery 벨류데이션 플러그인 사용시
                 if( !validation() ){       //화면 항목 점검 시작
                    return false;
                }
            },
            success:function(data) {
               if(data.result == true){
            	   if(data.resultDup == 'N'){
                       alert("Duplication");
                   }else{
                       alert("Complete the save");
                       location="/productAdjust.html"; 
                   }   
               }               
           },
           error:function(){alert("ERROR!");}
        }); 
    });

    
    
    /************************************************************************/
    /*                          textarea 글자 수 체크                       */
    /************************************************************************/
    /* textarea 체크 */
    var oldStr;
    function textAreaKyUp(obj){
        var str = obj.value;
        if(str.length <= 1000){
            oldStr = str;
            contents = "("+str.length+" / ";
            $("#cnt").html(contents);
        }else{
            alert("Limited string has been exceeded.");
            $("#pop_remark").val(oldStr);
        }
    };
    
    function validation(){

        var goodsName       = $("#goodsName").val();
        var mawb            = $("#mawb").val();
        var hawb          = $("#hawb").val();
        var batchNo          = $("#batchNo").val();
        var qty        = $("#qty").val();
        var adjustDate     = $("#adjustDate").val();
        
        if(goodsName==null   || goodsName=="") {   alert("Product Name required!!"); $("#goodsName").focus(); return false; }
        if(mawb==null        || mawb=="") { alert("Mawb required!!"); $("#mawb").focus(); return false; }
        if(hawb==null        || hawb=="") { alert("Hawb required!!"); $("#hawb").focus(); return false; }
        if(batchNo==null     || batchNo=="") { alert("BatchNo required!!"); $("#batchNo").focus(); return false; }
        if(qty==null         || qty=="") { alert("Qty required!!"); $("#qty").focus(); return false; }
        if(adjustDate==null   || adjustDate=="") { alert("AdjustDate required!!"); $("#adjustDate").focus(); return false; }
   
      return true;      
    } 


    /************************************************************************/
    /*                      상품 팝업 버튼 , 리턴값처리                     */
    /************************************************************************/
    /* 상품 팝업 버튼 */
    function onProductPopup(obj){
        
        window.open('/productPop.html', 'changeProductPop', 'width=615, height=450, toolbar=no, location=no, status=no, menubar=no, scrollbars=no');
    }

    function productPopValue(goodsCode, goodsName, unit, boxQty, hsCode, productCode, custCode, custName){

        $("#goodsCode").val(goodsCode);
        $("#goodsName").val(goodsName);   
    }
    
</script>
</head>
<body>
<div class="wrap">
    <form name="productAdjustWriteFrm" method="post" action="/saveProductAdjust.json">
    <div class="pagetitle">
        <h1>PRODUCT ADJUST/ INSERT</h1>
    </div>
    <div>
        <table class="TableST">
            <tr>
                <th>Product</th>
                <td>
                    <input type="text" class="inST40" name="goodsName" id="goodsName"/>
                    <img src='/images/web/bkn_zoom.gif' aligh='right' id='stockOutPop' onclick='onProductPopup(this);'>
                    <input type="hidden" class="inST40" name="goodsCode" id="goodsCode"/>
                </td>
            </tr>
            <tr>
                <th>MAWB</th>
                <td><input type="text" class="inST40" name="mawb" id="mawb"/></td>
            </tr>
            <tr>
                <th>HAWB</th>
                <td><input type="text" class="inST40" name="hawb" id="hawb"/></td>
            </tr>
            <tr>
                <th>Batch No</th>
                <td><input type="text" class="inST40" size="80" name="batchNo" id="batchNo"/></td>
            </tr>
            <tr>
                <th>Qty</th>
                <td><input type="text" class="inST40" size="80" name="qty" id="qty" maxlength="7"/></td>
            </tr>
            <tr>
                <th>Adjust Date</th>
                <td>
                    <input type="text" class="inSTR40" size="80" name="adjustDate" id="adjustDate"/>
                </td>
            </tr> 
            <tr>
               <th>Remarks<br><span id="cnt">(0 / </span>1000)</th>
               <td colspan="2"><textarea class="teST" wrap="virtual" id="remark" name="remark"></textarea></td>
            </tr>        
         </table>
    </div>
    <div class="bo_btn">        
        <ul class="btnst"><li class="a"><a href="#" id="reSetBtn" >INIT</a></li></ul>
        <ul class="btnst"><li class="a"><a href="#" id="onList" >LIST</a></li></ul>
        <ul class="btnst"><li class="a"><a href="#" id="saveBtn" >SAVE</a></li></ul>      
    </div>
    <input type="hidden" name="saveStatus" id="saveStatus" value="SAVE"/>
    </form>
</div>
</body>
</html>